<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<meta name="generator" content="PHPDoctor 2RC4 (http://peej.github.com/phpdoctor/)">
<meta name="when" content="Mon, 02 May 2011 02:46:56 +0000">

<link rel="stylesheet" type="text/css" href="../stylesheet.css">
<link rel="start" href="../overview-summary.html">

<title>helper.php (Cornice)</title>

</head>
<body id="file" onload="parent.document.title=document.title;">

<div class="header">
<h1>Cornice</h1>
<ul>
<li><a href="../overview-summary.html">Overview</a></li>
<li>Package</li><li>Class</li><li>Tree</li><li><a href="../overview-files.html">Files</a></li>
<li><a href="../deprecated-list.html">Deprecated</a></li>
<li><a href="../todo-list.html">Todo</a></li>
<li><a href="../index-all.html">Index</a></li>
</ul>
</div>

<div class="small_links">
<a href="../index.html" target="_top">Frames</a>
<a href="../source\helper.php.html" target="_top">No frames</a>
</div>
<hr>

<h1>helper.php</h1>
<div class="comment" id="overview_description"><p>============================================================================
Cornice PHP Framework & Website Builder
Freeware (f) 2011 by Inforo Software & Computer
============================================================================</p></div>

<hr>

<a name="line1"></a><pre><?php
<a name="line2"></a>/**
<a name="line3"></a> *============================================================================
<a name="line4"></a> * Cornice PHP Framework & Website Builder
<a name="line5"></a> * Freeware (f) 2011 by Inforo Software & Computer
<a name="line6"></a> *============================================================================
<a name="line7"></a> */
<a name="line8"></a> 
<a name="line9"></a>/**
<a name="line10"></a> * Class contains miscellaneous utils
<a name="line11"></a> * @author Nicola Dinh
<a name="line12"></a> * @version 2011.04.2217
<a name="line13"></a> */
<a name="line14"></a>class helper {
<a name="line15"></a>
<a name="line16"></a>  /**
<a name="line17"></a>   * Default instance level constructor
<a name="line18"></a>   * Just decorative, should not be called due to having only static methods
<a name="line19"></a>   */
<a name="line20"></a>  public function __construct() {
<a name="line21"></a>    //
<a name="line22"></a>  }
<a name="line23"></a>  
<a name="line24"></a>  /**
<a name="line25"></a>   * Trim trailing & tailing characters, also extra spaces in between
<a name="line26"></a>   * @param string $text The text to trim
<a name="line27"></a>   * @return string The trimmed text
<a name="line28"></a>   */
<a name="line29"></a>  public static function trim_neat($text) {
<a name="line30"></a>    $text = trim($text);
<a name="line31"></a>    while (strpos($text,chr(32).chr(32))!==false)
<a name="line32"></a>      $text = str_replace(chr(32).chr(32),chr(32),$text);
<a name="line33"></a>    return $text;
<a name="line34"></a>  }
<a name="line35"></a>  
<a name="line36"></a>  /**
<a name="line37"></a>   * Get current skin in cookie
<a name="line38"></a>   * @return string The name of skin (eg. 'sunshine')
<a name="line39"></a>   */
<a name="line40"></a>  public static function get_cur_skin() {
<a name="line41"></a>    return system::$skin;
<a name="line42"></a>  }
<a name="line43"></a>  
<a name="line44"></a>  /**
<a name="line45"></a>   * Get current language in cookie
<a name="line46"></a>   * @return string The name of language (eg. 'uk','ru',...)
<a name="line47"></a>   */
<a name="line48"></a>  public static function get_cur_lang() {
<a name="line49"></a>    return system::$lang;
<a name="line50"></a>  }
<a name="line51"></a>  
<a name="line52"></a>  /**
<a name="line53"></a>   * Dump object to file 'dump.txt'
<a name="line54"></a>   * @param object $objecct The object to dump
<a name="line55"></a>   */
<a name="line56"></a>  public static function dump($object) {
<a name="line57"></a>    ob_start();
<a name="line58"></a>    var_dump($object);
<a name="line59"></a>    $text = ob_get_clean();
<a name="line60"></a>    file_put_contents("dump.txt",$text);
<a name="line61"></a>  }
<a name="line62"></a>
<a name="line63"></a>  /**
<a name="line64"></a>   * Dump debug backtrace  
<a name="line65"></a>   */
<a name="line66"></a>  public static function dump_trace() {
<a name="line67"></a>    self::dump(debug_backtrace());
<a name="line68"></a>  }
<a name="line69"></a>  
<a name="line70"></a>  /**
<a name="line71"></a>   * Make URL with a custom param value
<a name="line72"></a>   * @param string $param The param in URL to add or replace
<a name="line73"></a>   * @param string $param_value The value to set
<a name="line74"></a>   * @return string The URL with param added or replaced
<a name="line75"></a>   */
<a name="line76"></a>  public static function make_url($param,$param_value) {   
<a name="line77"></a>    $validated_url = request::get_validated_url();
<a name="line78"></a>    $tokens = explode("_",$validated_url); 
<a name="line79"></a>    
<a name="line80"></a>    //convert to assoc array
<a name="line81"></a>    $array = array();
<a name="line82"></a>    for ($index=0; $index<count($tokens)/2; $index++)
<a name="line83"></a>      $array[$tokens[$index*2]] = $tokens[$index*2+1];
<a name="line84"></a>      
<a name="line85"></a>    //set value
<a name="line86"></a>    $array[$param] = $param_value;
<a name="line87"></a>    
<a name="line88"></a>    //combine into url
<a name="line89"></a>    $url = ""; 
<a name="line90"></a>    $last_key = lastkey($array);
<a name="line91"></a>    foreach ($array as $key=>$value) {
<a name="line92"></a>      $url .= $key."_".$value;
<a name="line93"></a>      if ($key!=$last_key)
<a name="line94"></a>        $url .= "_";
<a name="line95"></a>    }
<a name="line96"></a>    
<a name="line97"></a>    return $url; 
<a name="line98"></a>  }
<a name="line99"></a>  
<a name="line100"></a>  /**
<a name="line101"></a>   * Get URL for setting language
<a name="line102"></a>   * @param string $lang The language abbreviation (TLD extension)
<a name="line103"></a>   * @return string The relative URL with 'setlang' param
<a name="line104"></a>   */
<a name="line105"></a>  public static function get_lang_url($lang) {
<a name="line106"></a>    return self::make_url("setlang",$lang);
<a name="line107"></a>  }
<a name="line108"></a>  
<a name="line109"></a>  /**
<a name="line110"></a>   * Get captcha URL
<a name="line111"></a>   * @return string The url to captcha image
<a name="line112"></a>   */
<a name="line113"></a>  public static function get_captcha_url() {
<a name="line114"></a>    $skin = system::$skin;
<a name="line115"></a>    $module = request::get_module_name();
<a name="line116"></a>    return "skins/$skin/scripts/captcha.php?module=$module";
<a name="line117"></a>  }
<a name="line118"></a>  
<a name="line119"></a>  /**
<a name="line120"></a>   * Get captcha value
<a name="line121"></a>   * @return string The captcha value stored in session data
<a name="line122"></a>   */
<a name="line123"></a>  public static function get_captcha_value() {
<a name="line124"></a>    return session::get_value("captcha");
<a name="line125"></a>  }
<a name="line126"></a>  
<a name="line127"></a>  /**
<a name="line128"></a>   * Get server name (ie. 'localhost' or domain, the value configured in
<a name="line129"></a>   * Apache server config file.
<a name="line130"></a>   * @return string The server name
<a name="line131"></a>   */
<a name="line132"></a>  public static function get_server_name() {
<a name="line133"></a>    //SERVER_ADDR is the IP, not the name
<a name="line134"></a>    return strtolower($_SERVER["SERVER_NAME"]);
<a name="line135"></a>  }
<a name="line136"></a>  
<a name="line137"></a>  /**
<a name="line138"></a>   * Get script name (ie. the path & script file name after server name),
<a name="line139"></a>   * combines with protocol & server name will be the URL without query string.
<a name="line140"></a>   * If already URL-rewritten, this function returns the actual script file.
<a name="line141"></a>   * @return string The script path & script file name
<a name="line142"></a>   */
<a name="line143"></a>  public static function get_script_name() {
<a name="line144"></a>    //PHP_SELF has the same value but not popular
<a name="line145"></a>    //REQUEST_URI has the query string included
<a name="line146"></a>    return strtolower($_SERVER["SCRIPT_NAME"]);
<a name="line147"></a>  }
<a name="line148"></a>  
<a name="line149"></a>  /**
<a name="line150"></a>   * Get the path (after domain & before script file name) to requested script;
<a name="line151"></a>   * this path doesn't contain slashes at beginning & end;
<a name="line152"></a>   * this function fails if being called from somewhere else other than root
<a name="line153"></a>   * directory of Cornice.
<a name="line154"></a>   * @return string The path after domain & before file name
<a name="line155"></a>   */
<a name="line156"></a>  public static function get_script_path() {
<a name="line157"></a>    $script_name = self::get_script_name();
<a name="line158"></a>    $last_slash  = strrpos($script_name,"/");
<a name="line159"></a>    
<a name="line160"></a>    if ($last_slash===0)
<a name="line161"></a>      return "";
<a name="line162"></a>    else
<a name="line163"></a>      return substr($script_name,1,$last_slash-1);
<a name="line164"></a>  }
<a name="line165"></a>  
<a name="line166"></a>  /**
<a name="line167"></a>   * Get the URL to a local script; this function fails if being called from 
<a name="line168"></a>   * somewhere else other than root dir of Cornice; assume not using HTTPS;
<a name="line169"></a>   * if already URL-rewritten, this functions returns the actual URL.
<a name="line170"></a>   * @return string The URL to a local script, like being called from browser
<a name="line171"></a>   */
<a name="line172"></a>  public static function get_local_url($addin_path=null) {
<a name="line173"></a>    $server_name = self::get_server_name();
<a name="line174"></a>    $script_path = self::get_script_path();
<a name="line175"></a>    if ($addin_path!=null) {
<a name="line176"></a>      if (strlen($script_path)>0)
<a name="line177"></a>        return "http://$server_name/$script_path/$addin_path";
<a name="line178"></a>      else
<a name="line179"></a>        return "http://$server_name/$addin_path";
<a name="line180"></a>    }
<a name="line181"></a>    else {
<a name="line182"></a>      if (strlen($script_path)>0)
<a name="line183"></a>        return "http://$server_name/$script_path";
<a name="line184"></a>      else
<a name="line185"></a>        return "http://$server_name";
<a name="line186"></a>    }
<a name="line187"></a>  }//get_local_url
<a name="line188"></a>}</pre>
<div class="header">
<h1>Cornice</h1>
<ul>
<li><a href="../overview-summary.html">Overview</a></li>
<li>Package</li><li>Class</li><li>Tree</li><li><a href="../overview-files.html">Files</a></li>
<li><a href="../deprecated-list.html">Deprecated</a></li>
<li><a href="../todo-list.html">Todo</a></li>
<li><a href="../index-all.html">Index</a></li>
</ul>
</div>

<div class="small_links">
<a href="../index.html" target="_top">Frames</a>
<a href="../source\helper.php.html" target="_top">No frames</a>
</div>
<hr>

<p id="footer">This document was generated by <a href="http://peej.github.com/phpdoctor/">PHPDoctor: The PHP Documentation Creator</a></p>

</body>

</html>